package logic

import (
	"context"
	"errors"
	"person/model/mysql"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserShowLogic) UserShow(in *personrpc.UserShowRequest) (*personrpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	err := user.FindUserById(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("用户不存在")
	}
	
	return &personrpc.UserShowResponse{
		Username: user.Username,
		Password: user.Password,
		UserId:   int64(user.ID),
	}, nil

}
